package com.gjintel.business.navset.dao.Impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.gjintel.business.navset.dao.INavManageDao;
import com.gjintel.business.navset.model.Nav;
import com.gjintel.sdk.base.dao.HibernateGenericDAO;
import com.gjintel.sdk.base.dao.Page;
import com.gjintel.sdk.base.dao.Sort;
import com.gjintel.sdk.util.StringUtil;


/**
 * @description 文章类型数据处理实现
 * @author Ant-K
 * @date 2016-3-16 下午19:38:39
 */

@Repository("NavManageDao")
public class NavManageDaoImpl extends HibernateGenericDAO implements INavManageDao{

	@SuppressWarnings("unchecked")
	public List<Nav> findAll() {
		String hql = "from Nav g where g.flag=0 order by g.disSort asc";
		return this.find(hql);
	}

	@SuppressWarnings("unchecked")
	public void findAll(Page page, Nav nav, Sort sort) {
		StringBuffer hql = new StringBuffer("from Nav g where g.flag=0 and g.id!=1 ");
		List<String> params = new ArrayList<String>(2);
		if (nav != null) {
			if (!StringUtil.isEmpty(nav.getName())) {
				hql.append(" and g.name like ? ");
				params.add("%" + nav.getName().trim() + "%");
			}
			if (!StringUtil.isEmpty(nav.getPid())) {
				hql.append(" and g.pid=? ");
				params.add(nav.getPid().trim());
			}
		}
		hql.append(" order by g.disSort asc");
		this.findAsPage(hql.toString(), page, sort, "g", false, params.toArray());
	}
}
